package com.forum;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;

public class ForumActivity extends Activity implements OnClickListener {
	
	//ARRAYS
	
	public int[] textBoxMap = {
			R.id.editText1,
			R.id.editText2,
			R.id.editText3,
			R.id.editText4
	};
	
	public int[] buttonMap = {
			R.id.button1
	};
	
	//PUBLICS
	
	public Button button;
	public EditText[] textBox;
	public int btnId;
	public String[] output;
	public String spin;
	
	
    //ONCREATE
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //BUTTON AND TEXT BOX
        textBox = new EditText[4];
        button = (Button)findViewById(R.id.button1);
        
        
        //FOR LOOP FOR TEXT BOX
        for(int i = 0; i < textBox.length; i++ ){
        	textBox[i] = (EditText)findViewById(textBoxMap[i]);
        	
        button.setOnClickListener(this); 
        
        //SPINNER
        Spinner spinner1 = (Spinner)findViewById(R.id.spinner1);
        
        ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.Courses, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        
        spinner1.setAdapter(adapter);
        					
        }
    }
        

    //ON CLICK
	public void onClick(View v) {
		btnId = v.getId();
		output = new String[4];
		
		//SPINNER
		Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
		spin = spinner1.getSelectedItem().toString();
		
		//FOR LOOP FOR GETTING TEXT TO STRING
		for(int i = 0; i < textBox.length; i++){
			output[i] = textBox[i].getText().toString();
		}
			
		
		String everything = "Name: " + output[0] + "\n" + "Age: " + output[1] + "\n" + "Hometown: " + output[2] + "\n" + "RoomNumber: " + output[3] + "\n" + "Course: " + spin;
		
		Toast.makeText(getApplicationContext(), everything, Toast.LENGTH_LONG).show();
		
		for( int i = 0; i < buttonMap.length; i++ ){
			if(btnId == buttonMap[i]) {
				btnId = i;
			}
		}
		
	}
}